/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-11-02
 * Time: 16:44
 */
//这里使用字符串类型
class MyBlockingQueue {
    private String[] data = null;
    //队头
    private int head = 0;
    //队尾
    private int tail = 0;
    //元素个数
    private int size = 0;

    public MyBlockingQueue(int capacity) {
        data = new String[capacity];
    }

    //添加元素
    public void put(String elem) {
        if(size >= data.length) {
            //队列满了阻塞
            return;
        }
        data[tail] = elem;
        tail++;
        if(tail >= data.length) {
            tail = 0;
        }
        size++;
    }
    //删除元素
    public String take() {
        if(size == 0) {
            //此时队列为空阻塞
            return null;
        }
        String s = data[head];
        head++;
        if(head >= data.length) {
            head = 0;
        }
        size--;
        return s;
    }
}
public class Demo5 {

}
